package com.neusoft.yuejian_01.model;

import com.neusoft.yuejian_01.base.BaseModel;
import com.neusoft.yuejian_01.javabean.ProfessorBean;
import com.neusoft.yuejian_01.javabean.ProfessorCourseBean;
import com.neusoft.yuejian_01.listener.RetrofitListener;
import com.neusoft.yuejian_01.service.ProfessorService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/9/30.
 */

public class ProfessorModel extends BaseModel {
    //大师列表
    public void professorlist(final RetrofitListener listener){
        this.flag = Const.ProfessorList;
        ProfessorService professorService = retrofit.create(ProfessorService.class);
        Call<List<ProfessorBean>> call = professorService.getProfessorlist();
        Callback<List<ProfessorBean>> callback = new Callback<List<ProfessorBean>>() {
            @Override
            public void onResponse(Call<List<ProfessorBean>> call, Response<List<ProfessorBean>> response) {
                List<ProfessorBean> professorBean = response.body();
                listener.onSuccess(professorBean,flag);
            }
            @Override
            public void onFailure(Call<List<ProfessorBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    //大师课程列表
    public void professorcourselist(String pm_id,final RetrofitListener listener){
        this.flag = Const.ProfessorCourseList;
        ProfessorService professorService = retrofit.create(ProfessorService.class);
        Call<List<ProfessorCourseBean>> call = professorService.getPclist(pm_id);
        Callback<List<ProfessorCourseBean>> callback = new Callback<List<ProfessorCourseBean>>() {
            @Override
            public void onResponse(Call<List<ProfessorCourseBean>> call, Response<List<ProfessorCourseBean>> response) {
                List<ProfessorCourseBean> professorCourseBean = response.body();
                listener.onSuccess(professorCourseBean,flag);
            }
            @Override
            public void onFailure(Call<List<ProfessorCourseBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    //大师详情
    public void Pmdetail(String m_id,final RetrofitListener listener){
        this.flag = Const.ProfessorDetail;
        ProfessorService professorService = retrofit.create(ProfessorService.class);
        Call call = professorService.getPmdetail(m_id);
        call.enqueue(new Callback<ProfessorBean>(){
            @Override
            public void onResponse(Call<ProfessorBean> call, Response<ProfessorBean> response){
                ProfessorBean Pmdetail = response.body();
               listener.onSuccess(Pmdetail,flag);
            }
            @Override
            public void onFailure(Call<ProfessorBean> call, Throwable t){
                listener.onFail();
            }
        });
    }
}

